package com.fawvwebanma.service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Component;

import com.fawvwebanma.api.BuyTicketApi;
import com.fawvwebanma.dto.PersonDto;
import com.fawvwebanma.dto.ResultData;
import com.fawvwebanma.dto.TicketDto;

import lombok.extern.slf4j.Slf4j;

/**
 * @author jieye.ren
 * @date 2021/3/11
 */
@Component
@DubboService
@Slf4j
public class BuyTicketsService implements BuyTicketApi {
    @Override
    public ResultData<List<TicketDto>> buyTicket(String trainNum, String leaveStationName, String arriveStationName,
        String depatureDate, List<PersonDto> personDtos) {
        // 生成一个UUID作为订单编号
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        List<TicketDto> tickets = new ArrayList<>();
        String seatNum = "seatNum";
        for (PersonDto person : personDtos) {
            TicketDto ticket = new TicketDto(person.getPersonId(), uuid, trainNum, depatureDate, "3号车厢", seatNum, 2,
                leaveStationName, arriveStationName, 1, 200.0);
            tickets.add(ticket);
        }
        return ResultData.success(tickets);
    }
}
